layui.config({
  base:'scripts/'
}).extend({
  httpService: 'http.service',
  httpRouter: 'http.service',
  DateFormat: 'dateformat'
});

layui.use(['jquery', 'layer', 'form', 'table', 'element', 'laydate', 'httpService', 'httpRouter'], function(){

  var table = layui.table,
    form = layui.form,
    element = layui.element,
    laydate = layui.laydate,
    $ = layui.jquery,
    http = layui.httpService,
    httpRouter = layui.httpRouter;








  /*获取患者姓名列表*/
  function getBednoList() {
    http.get(httpRouter.userInfo,function (res) {
      console.log(res.records);
    });
  }
  getBednoList()
  /*获取复核人列表*/
  function getReviewuserList() {
    http.get(httpRouter.reviewUserInfo,function (res) {
      console.log(res.records);
    });
  }
  getReviewuserList()
  /*获取临床医生列表*/
  function getClincianList() {
    http.get(httpRouter.clinicianinfo,function (res) {
      console.log(res.records);
    });
  }
  getClincianList()
  /*获取筛查明细列表*/
  function getSearchList() {
    http.get(httpRouter.searchmanage,function (res) {
      console.log(res.records);
    });
  }
  getSearchList()



  /*打印结果*/
  function getSearchList() {
   /* http.get(httpRouter.searchmanage,function (res) {
      console.log(res.records);
    });*/
  }
  getSearchList();
  /*复核*/
  function check() {
    http.get(httpRouter.checkrisk,function (res) {
      console.log(res.records);
    });
  }

  /*关注患者*/
  function payattention() {
    http.get(httpRouter.payattention,function (res) {
      console.log(res.records);
    });
  }

  var params = {
    startdatetime:"",
    enddatetime:"",
    depNo:"",
    bedNo:"",
    userNo:"",
    reviewerNo:"",
    clinicianNo:"",
    inHospitalState:"",
    screenState:"",
    isRisk:"",
    reviewerResult:"",
    isFollow:""
  }
  var page = 1;


  function getSearchmanage() {
    var param = "&startdatetime="+params.startdatetime
      +"&enddatetime="+params.enddatetime
      +"&depNo="+params.depNo
      +"&bedNo="+params.bedNo
      +"&userNo="+params.userNo
      +"&reviewerNo="+params.reviewerNo
      +"&clinicianNo="+params.clinicianNo
      +"&inHospitalState="+params.inHospitalState
      +"&screenState="+params.screenState
      +"&isRisk="+params.isRisk
      +"&reviewerResult="+params.reviewerResult
      +"&isFollo="+params.isFollo
      +"&page="+page
      +"&limit="+10;
    http.post(httpRouter.searchmanage,param,function (res) {
      searchmanage(res);
    });
  }
  getSearchmanage();

  function searchmanage(data) {
    console.log(data);
    table.render({
      elem: '#demo'
      ,data:data.records
      ,height: 500
      ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
        layout: ['count', 'prev', 'page', 'next'] //自定义分页布局
        //,curr: 5 //设定初始在第 5 页
        ,groups: 5 //只显示 1 个连续页码
        ,first: false //不显示首页
        ,last: false //不显示尾页
      }
      ,cols: [[
        {type: 'checkbox'}
        ,{field:'isFollow', title:'关注', width: 60, templet: '#checkboxTpl'}
        ,{field:'depName', title:'科室'}
        ,{field:'bedName', title:'床号', width: 80}
        ,{field:'clinicianName', title:'临床医生', width: 90}
        ,{field:'userName', title: '患者', width: 90}
        ,{field:'sex', title: '性别', width: 60 ,templet:'<span>{{d.sex == 1? "男" : "女"}}</span>'}
        ,{field:'age', title: '年龄', width: 60}
        ,{field:'inHospitalData', title: '入院日期'}
        ,{field:'searchDate', title: '筛查时间'}
        ,{field:'reviewerName', title: '复核人'}
        ,{field:'reviewerDate', title: '复核时间'}
        ,{field:'reviewerResult', title: '复核结果',templet:'<span>{{d.reviewerResult == 1 ? "有风险" : "无风险"}}</span>'}
        ,{field:'diagnosisResult', title: '营养诊疗建议'}
        ,{field:'lastTimeSearchDate', title: '上次筛查时间'}
        ,{field:'searchResult', title: '筛查结果',templet:'<span>{{d.searchResult == 1 ? "有风险" : "无风险"}}</span>'}
        ,{field:'screenState', title: '类型',templet:'<span>{{d.screenState == 1 ? "初筛" : "复筛"}}</span>'}
      ]]
    });
  }




  //选择科室
  $('#btn-ks').on('click', function(){
    http.get(httpRouter.cnisdeplistinfo,{},function (res) {
      $('#modal_dep').empty();
      $.each(res.records,function(index,obj){
        $('#modal_dep').append(
          '<label>' +
          '<input type="checkbox" name="" title="发呆" lay-skin="primary">' +
          obj.DepartmentName +
          '</label>');
      });
    });


  });

  //选择筛选条件
  $('#btn-ch').on('click', function(){
    layer.open({
      type: 1
      ,title: '选择筛选条件'
      ,closeBtn: false
      ,area: '700px;'
      ,shade: 0.8
      ,id: 'LAY_sxtj'
      ,btn: ['确定', '取消']
      ,btnAlign: 'c'
      ,content: $('#modal_sxtj')
    });
  });

  //打印筛查结果
  $('#btn-print').on('click', function(){
    var checkStatus = table.checkStatus('searchmanage'),
      data = checkStatus.data,
      listId = [];
    if(data.length > 0) {
      for (var i in data) {
        listId.push(data[i].userNo);
      }
      console.log(listId);
      http.post(httpRouter.printresult,listId,function (res) {
        // printTable.reload(table.reload('printTable', {
        //   where: {
        //     userNoArray: listId
        //   }
        // })
        // layer.close(res)
      });
      layer.open({
        type: 1
        ,title: '打印筛查结果'
        ,closeBtn: false
        ,area: '900px;'
        ,shade: 0.8
        ,id: 'LAY_print'
        ,btn: ['确定', '取消']
        ,btnAlign: 'c'
        ,content: $('#modal_print')
      });
    }else{
      layer.msg('请选择需要打印的数据');
    }
  });






  //增加符合结果
  $('#btn-fs').on('click', function(){
    layer.open({
      type: 1
      ,title: '增加符合结果' //不显示标题栏
      ,closeBtn: false
      ,area: '400px;'
      ,shade: 0.8
      ,id: 'LAY_fhjg' //设定一个id，防止重复弹出
      ,btn: ['确定', '取消']
      ,btnAlign: 'c'
      ,content: $('#modal_fhjg')
    });
    laydate.render({
      elem: '#test1'
    });
  });

});
